package com.heima.admin.service.imp;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.admin.mapper.ApUserRealnameMapper;
import com.heima.admin.service.ApUserRealnameService;
import com.heima.apis.user.SelectUser;
import com.heima.apis.wemedia.IWmChannel;
import com.heima.common.exception.CustomException;
import com.heima.model.admin.dtos.PageDto;
import com.heima.model.admin.pojos.ApUserRealname;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.wemedia.pojos.WmUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

/**
 * <p>
 * APP实名认证信息表 服务实现类
 * </p>
 *
 * @author itheima
 */
@Slf4j
@Service
@Transactional
public class ApUserRealnameServiceImpl extends ServiceImpl<ApUserRealnameMapper, ApUserRealname> implements ApUserRealnameService {


    @Override
    public ResponseResult authFail(PageDto pageDto) {
        //验证参数
        if (pageDto.getId()==null){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        ApUserRealname apUserRealname = getById(pageDto.getId());
        if (apUserRealname==null){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        apUserRealname.setStatus((short) 2);
        apUserRealname.setReason(pageDto.getMsg());
        updateById(apUserRealname);
        return ResponseResult.okResult("驳回成功");
    }
    @Autowired
    private SelectUser selectUser;
    @Autowired
    private IWmChannel iWmChannel;
    @Override
    public ResponseResult authPass(PageDto pageDto) {
        //验证参数
        if (pageDto.getId()==null){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        ApUserRealname apUserRealname = getById(pageDto.getId());
        if (apUserRealname==null){
            throw new CustomException(AppHttpCodeEnum.PARAM_INVALID);
        }
        apUserRealname.setStatus((short) 9);
        ApUser apUser = selectUser.selectuser(apUserRealname.getUserId());
        WmUser wmUser = new WmUser();
        wmUser.setName(apUser.getName());
        wmUser.setPassword(apUser.getPassword());
        wmUser.setPhone(apUser.getPhone());
        wmUser.setApUserId(apUser.getId());
        wmUser.setStatus(9);
        wmUser.setCreatedTime(new Date());
        wmUser.setType(0);
        iWmChannel.insertwmuser(wmUser);
        updateById(apUserRealname);

        return null;
    }
}
